﻿using TomatoClock.Models;
using TomatoClock.Services;
using TomatoClock.ViewModels;
using MaterialSkin;
using MaterialSkin.Controls;


namespace TomatoClock.Views
{
    public partial class Enroll : Form
    {
        private DataService dataService;
        private readonly MaterialSkinManager materialSkinManager;
        public Enroll(DataService dataService)
        {
            InitializeComponent();
            this.dataService = dataService;
            /*materialSkinManager = MaterialSkinManager.Instance;
            materialSkinManager.EnforceBackcolorOnAllComponents = true;
            materialSkinManager.AddFormToManage(this);
            materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
            materialSkinManager.ColorScheme = new ColorScheme(
                       Primary.Cyan700,
                       Primary.Cyan900,
                       Primary.Cyan500,
                       Accent.DeepOrange200,
                       TextShade.WHITE);*/
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Enroll_Load(object sender, EventArgs e)
        {

        }

        private void materialButton1_Click(object sender, EventArgs e)
        {
            Start start = new Start(dataService);
            this.Hide();
            start.ShowDialog();
        }

        private void materialButton2_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text;
            string password1 = textBox2.Text;
            string password2 = textBox3.Text;

            Login login = new Login(dataService);

            if (password1 != password2)
            {
                MessageBox.Show("您两次输入的密码不同，请重新输入！");
            }
            else
            {
                if (dataService.EnrollUser(username))
                {
                    MessageBox.Show("该账号已经注册过了，请更换账号！");
                }
                else
                {
                    User newUser = new User(username, password1); // 创建新用户对象
                    dataService.AddUser(newUser);
                    MessageBox.Show("注册成功！");
                    this.Hide();
                    login.ShowDialog();

                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text;
            string password1 = textBox2.Text;
            string password2 = textBox3.Text;

            Login login = new Login(dataService);

            if (password1 != password2)
            {
                MessageBox.Show("您两次输入的密码不同，请重新输入！");
            }
            else
            {
                if (dataService.EnrollUser(username))
                {
                    MessageBox.Show("该账号已经注册过了，请更换账号！");
                }
                else
                {
                    User newUser = new User(username, password1); // 创建新用户对象
                    dataService.AddUser(newUser);
                    MessageBox.Show("注册成功！");
                    this.Hide();
                    login.ShowDialog();

                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Start start = new Start(dataService);
            this.Hide();
            start.ShowDialog();
        }
    }
}
